<template>
  <div class="plan-item">
    <div class="title">
      {{ plan.name }}
    </div>
    <div
      class="item"
      v-for="(item, i) in plan.list"
      :key="i"
    >
      <div class="text">
        <div class="name">
          {{ item.name }}<span>（{{ item.sliceNum }}片）</span>
        </div>
        <div class="val">
          开始时间：<span>{{ item.gmtStart | timeDate("YYYY-MM-DD") }}</span>
        </div>
        <div class="val">
          结束时间：<span>{{ item.gmtEnd | timeDate("YYYY-MM-DD") }}</span>
        </div>
      </div>
      <div class="info">
        <div class="day">
          施工天数{{ constructionDays(item) }}天
        </div>
        <div
          class="edit"
          @click="edit(item)"
        >
          修改>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "PlanItem",
  props: {
    plan: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {};
  },
  methods: {
    edit(item) {
      this.$emit("edit", item);
    },
    constructionDays(item) {
      let start = new Date(this.$options.filters.timeDate(item.gmtStart));
      let end = new Date(this.$options.filters.timeDate(item.gmtEnd));
      return Math.ceil((end - start) / (1000 * 60 * 60 * 24));
    },
  },
};
</script>

<style lang="scss" scoped>
.plan-item {
  padding: 15px;
  .title {
    padding-left: 15px;
    font-weight: 700;
    font-size: 18px;
    line-height: 30px;
    position: relative;
    margin-bottom: 10px;
    &::before {
      content: "";
      position: absolute;
      display: block;
      height: 20px;
      top: 50%;
      left: 0;
      width: 4px;
      background: #3e88e2;
      border-radius: 2px;
      margin-top: -10px;
    }
  }
  .item {
    padding: 10px 0;
    border-bottom: 1px solid #f5f5f7;
    display: flex;
    .text {
      flex: 1;
      width: 0;
      .name {
        font-size: 16px;
        color: #333;
        span {
          color: #999;
        }
      }
      .val {
        margin: 5px 0;
        font-size: 14px;
        color: #999;
        span {
          color: #666;
        }
      }
    }
    .info {
      display: flex;
      flex-direction: column;
      .day {
        line-height: 30px;
      }
      .edit {
        flex: 1;
        height: 0;
        color: #5883a4;
        text-decoration: underline;
        display: flex;
        justify-content: flex-end;
        align-items: center;
      }
    }
  }
}
</style>
